package com.byxy.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.byxy.entity.User;
import com.byxy.service.UserService;

import com.opensymphony.xwork2.ActionSupport;


public class UserLoginAction extends ActionSupport {
	private String username;
	private String password;

	@Resource
	private UserService userSerivce;

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		return SUCCESS;
	}
	public String login() {
		System.out.println(username+"    "+password);
		
		User user=new User();
		user.setUsername(username);
		user.setPassword(password);
		User user2=userSerivce.login(user);
		//System.out.println("++++++++"+user);
		if (user2!=null) {
			HttpSession session = ServletActionContext.getRequest().getSession();
			session.setAttribute("uname", user2.getUsername());
			return SUCCESS;
		}
		return ERROR;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}
